package com.design.pattern.structure.conposite.demo.safe;

import java.util.ArrayList;
import java.util.List;

public class Folder extends Directory{
    private Integer level;
    private List<Directory> dirs;

    public Folder(String name, Integer level) {
        super(name);
        this.level = level;
        this.dirs = new ArrayList<>();
    }

    @Override
    public void show() {
        System.out.println(this.name);
        for(Directory d : dirs) {
            if(this.level != null) {
                for(int i = 0; i < this.level; i++)
                    if(i == 0)
                        System.out.print("  ");
                    System.out.print("-");
            }
            d.show();
        }
    }


    public Directory get(int index) {
        return dirs.get(index);
    }

    public boolean remove(Directory directory) {
        return this.dirs.remove(directory);
    }

    public boolean add(Directory directory) {
        return this.dirs.add(directory);
    }

    public void list(){
        for(Directory d : dirs) {
            System.out.println(d.name);
        }
    }
}
